<?php
declare(ENCODING = 'utf-8');

/*
 * CR_NodeTypeDefinition.php created on 14 avr. 08 
 * Author: Rodrigue Le Gall
 * 
 * This file is inspired by the project Typo3
 *
 * RPortal is an open source web based Content Management System
 * Copyright (C) 2002-2008  Rodrigue Le Gall
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * A NodeTypeDefinition
 *
 * @package CR
 */
class CR_NodeTypeDefinition implements phpCR_NodeTypeDefinitionInterface {

	/**
	 * @var CR_StorageAccess
	 */
	protected $storageAccess;

	/**
	 * @var integer
	 */
	protected $nodeTypeId;

	/**
	 * @var string
	 */
	protected $name;

	/**
	 * Constructs a NodeTypeDefinition
	 *
	 * @param integer $nodeTypeId The internal id of the nodetype
	 * @param CR_StorageAccessInterface $storageAccess
	 * @return void
	 * @todo Check node type handling
	 */
	public function __construct($nodeTypeId, CR_StorageAccessInterface $storageAccess) {
		$this->nodeTypeId = $nodeTypeId;
		$this->storageAccess = $storageAccess;

		$rawNodeTypeData = $this->storageAccess->getRawNodeTypeById($this->nodeTypeId);
		$this->name = $rawNodeTypeData['name'];
	}

	/**
	 * Returns the name of the node type.
	 *
	 * In implementations that support node type registration (see 6.6 Node
	 * Type Registration), if this NodeTypeDefinition object is actually a
	 * newly-created empty NodeTypeTemplate, then this method will return
	 * NULL.
	 *
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * Returns the node type ID
	 *
	 * @return integer ID of node type
	 */
	public function getId() {
		return $this->nodeTypeId;
	}
}
